package com.jinsi.controller.ylt;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YltConstant;
import com.jinsi.pojo.SyDiscountsIssuance;
import com.jinsi.service.ylt.UserCouponService;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @ClassName UserCouponController
 * @Content 用户优惠券Controller
 * @Author 姚龙腾
 * @Date 2022/10/12 11:53
 */
@RestController
@Slf4j
public class UserCouponController {
    @Autowired
    private UserCouponService userCouponService;


    /**
     * 查询看所有信息(模糊查询所需的信息)
     * @param page
     * @param limit
     * @param userAccount
     * @param userName
     * @return R
     */
    @RequestMapping("/getUserCouponList")
    public R getUserCouponList(Integer page, Integer limit, String userAccount, String userName){
        PageHelper.startPage(page,limit);
        List<SyDiscountsIssuance> list = userCouponService.getAll(userAccount, userName);
        PageInfo<SyDiscountsIssuance> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }


    /**
     * 获取优惠劵剩余数量
     * @param couponArray
     * @param userArrayLength
     * @return R
     */
    @RequestMapping("/getCouponNumById")
    public R getCouponNumById( @RequestParam("couponArray") String couponArray,Integer userArrayLength){
        String[] couponArr = couponArray.split(",");
        List<Integer> list = userCouponService.getCouponNum(couponArr, userArrayLength);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                list,
                (long) list.size());
    }

}
